package net.pimpas.web.jsf.resourcemanager;

import javax.faces.context.FacesContext;

import net.pimpas.logging.serviceprovider.LoggingServiceProvider;
import net.pimpas.logging.serviceprovider.LoggingServiceProviderFactoryImpl;

public class ResourceHandler implements org.apache.myfaces.renderkit.html.util.ResourceHandler {
	private static final LoggingServiceProvider logger = LoggingServiceProviderFactoryImpl.getLoggingServiceProvider(ResourceHandler.class);
	
	private Class component;
	private String resource;
	
	public ResourceHandler(Class component) {
		this.setComponent(component);
	}
	
	public void configure(String resource) {
		this.setResource(resource);
	}

	public Class getResourceLoaderClass() {
		return ResourceLoader.class;
	}

	public String getResourceUri(FacesContext context) {
		StringBuffer uri = new StringBuffer(this.getComponent().getName());
		uri.append("/");
		if(this.getResource() != null) uri.append(this.getResource());
		String result = new String(uri);
		logger.debug("[RESOURCE HANDLER]: Returning Resource URI ("+result+")");
		return result;
	}

	public Class getComponent() {
		return component;
	}

	public void setComponent(Class component) {
		this.component = component;
	}

	public String getResource() {
		return resource;
	}

	public void setResource(String resource) {
		this.resource = resource;
	}
}